package com.ruoyi.web.controller.books;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.books.domain.BooksMake;
import com.ruoyi.books.service.IBooksMakeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 非遗制作流程Controller
 *
 * @author ruoyi
 * @date 2024-03-28
 */

@Anonymous
@RestController
@RequestMapping("/books/make")
public class BooksMakeController extends BaseController
{
    @Autowired
    private IBooksMakeService booksMakeService;

    /**
     * 查询非遗制作流程列表
     */
//    @PreAuthorize("@ss.hasPermi('books:make:list')")
    @GetMapping("/list")
    public TableDataInfo list(BooksMake booksMake)
    {
        startPage();
        List<BooksMake> list = booksMakeService.selectBooksMakeList(booksMake);
        return getDataTable(list);
    }

    /**
     * 导出非遗制作流程列表
     */
//    @PreAuthorize("@ss.hasPermi('books:make:export')")
    @Log(title = "非遗制作流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BooksMake booksMake)
    {
        List<BooksMake> list = booksMakeService.selectBooksMakeList(booksMake);
        ExcelUtil<BooksMake> util = new ExcelUtil<BooksMake>(BooksMake.class);
        util.exportExcel(response, list, "非遗制作流程数据");
    }

    /**
     * 获取非遗制作流程详细信息
     */
//    @PreAuthorize("@ss.hasPermi('books:make:query')")
    @GetMapping(value = "/{makeId}")
    public AjaxResult getInfo(@PathVariable("makeId") Long makeId)
    {
        return success(booksMakeService.selectBooksMakeByMakeId(makeId));
    }

    /**
     * 新增非遗制作流程
     */
//    @PreAuthorize("@ss.hasPermi('books:make:add')")
    @Log(title = "非遗制作流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BooksMake booksMake)
    {
        return toAjax(booksMakeService.insertBooksMake(booksMake));
    }

    /**
     * 修改非遗制作流程
     */
//    @PreAuthorize("@ss.hasPermi('books:make:edit')")
    @Log(title = "非遗制作流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BooksMake booksMake)
    {
        return toAjax(booksMakeService.updateBooksMake(booksMake));
    }

    /**
     * 删除非遗制作流程
     */
//    @PreAuthorize("@ss.hasPermi('books:make:remove')")
    @Log(title = "非遗制作流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{makeIds}")
    public AjaxResult remove(@PathVariable Long[] makeIds)
    {
        return toAjax(booksMakeService.deleteBooksMakeByMakeIds(makeIds));
    }
}
